//
//  ZQMoneyManger.m
//  jianzhik
//
//  Created by huami on 2018/8/28.
//  Copyright © 2018年 WKWebView. All rights reserved.
//
#import <MJExtension/MJExtension.h>
#import "ZQMoneyModels.h"
#import "ZQMoneySettingPage.h"
#import "ZQMoneyManger.h"
#import "ZQMoneyCell.h"
#import "ZQDataManger.h"
@interface ZQMoneyManger ()
/** listArr */
@property (nonatomic, strong) NSMutableArray <ZQMoneyModels *> *listMuArr;
@end

@implementation ZQMoneyManger
- (NSMutableArray<ZQMoneyModels *> *)listMuArr
{
    if (!_listMuArr) {
        _listMuArr = [[NSMutableArray alloc] init];
    }
    return _listMuArr;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [ZQAFHelper afnetworkRequestWithGetURL:@"/v1/user/listcoin" parameters:parameters view:self.view finishedBlcok:^(NSDictionary *dict) {
        //        dict[Data]
        self.listMuArr = [ZQMoneyModels mj_objectArrayWithKeyValuesArray:dict[@"Data"]];
        if (self.listMuArr.count > 0) {
            NSMutableArray *marr = [NSMutableArray array];
            [self.listMuArr enumerateObjectsUsingBlock:^(ZQMoneyModels * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [marr addObject:obj.Symbol];
            }];
            [ZQDataManger shareIntance].bTypeListArr = marr;
        } else {
            [ZQDataManger shareIntance].bTypeListArr = @[];
        }
    
        [UIHelper dismissLoadingInView:self.view];
        [self.tableView reloadData];
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.footButton setTitle:@"添加新币种" forState:UIControlStateNormal];
    [self.footButton addTarget:self action:@selector(addMoney) forControlEvents:UIControlEventTouchUpInside];
    [self registerCell:[ZQMoneyCell class]];
    RegisterNotify(@"deleteMoney", @selector(tabviewLoadData:))
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

}

- (void)dealloc
{
    RemoveNofify;
}

- (void)tabviewLoadData:(NSNotification *)noti
{
    NSDictionary  *dic = [noti userInfo];
    
    ZQMoneyModels *model = dic[@"model"];
    [self.listMuArr removeObject:model];
    
    [self.tableView reloadData];

}

- (void)addMoney
{
    ZQMoneySettingPage *vc = [ZQMoneySettingPage new];
    vc.title = [self.footButton currentTitle];
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listMuArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 116;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ZQMoneyCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID  forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.models = self.listMuArr[indexPath.row];
    
    return cell;
}

@end
